package com.example.springmvc.config;

import com.example.springmvc.interceptor.RequestAttrInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @Description:
 * @Author: lijiewei
 * @Date: 2020/7/13$ 23:46$
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/**")

                .allowedOrigins("*")

                .allowCredentials(true)

                .allowedMethods("GET", "POST", "DELETE", "PUT")

                .maxAge(3600);

    }

    //注册拦截器
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        InterceptorRegistration registration = registry.addInterceptor(new RequestAttrInterceptor());
//        //所有路径都被拦截
//        registration.addPathPatterns("/**");
//        //添加不拦截路径
//        registration.excludePathPatterns("/**/*.html", "/**/*.js", "/**/*.css");
//    }
}
